
import mx.collections.ICollectionView;
import mx.collections.XMLListCollection;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

////////////////////////////////////////////////
//业务方法
////////////////////////////////////////////////
[Bindable]
private var serverURL:String="test_init.xml";
[Bindable]
private var chartTitle:String = "";

private function initBiz():void{
	displayOrgChartFor("0");
	//注册供Javascript调用的方法
    //调用示例详见 html-template/index.template.html
    // Interactive with JavaScript
    if(ExternalInterface.available){
		ExternalInterface.addCallback("displayOrgChartFor", displayOrgChartFor);
		ExternalInterface.addCallback("setTitle", setTitle);
    }
}
public function setTitle(title:String):void{
	chartTitle = title;
}
public function displayOrgChartFor(id:String, industryId:String="0"):void{
	currentIndustryId = industryId;
	var o:Object;
	if(isFirstTime){
		o = {id:id, deptType:0, industryId:currentIndustryId, tmode:"asshole"};
		isFirstTime = false;
	}else{
		o = {id:id, deptType:1, industryId:currentIndustryId, tmode:"asshole"};
	}
	if(id == "0"  && industryId != "0"){
		o.deptType = 0;
	}
	addToHistory(o);
	
	displayOrgChart(o);
}

private var isFirstTime:Boolean = true;
public function displayOrgChart(params:Object):void{
	updateURL();
	
	httpService.send(params); 
	trace("parameters{id:"+params.id+", deptType:"+params.deptType+", industryId:"+params.industryId+"]");
}

private function resultHandler(event:ResultEvent):void{
	//trace("result="+event.result);
	if(event.result != null && event.result is XML){
		var result:XML = event.result as XML;
		orgTree.dataProvider = result;
		var data:ICollectionView = new XMLListCollection(new XMLList+result);
		oc.dataProvider = data;
		oc.visible = true;
	}
} 
private function faultHandler(event:FaultEvent):void{
	trace(event+"");
	trace(event.message.body+"");
	Alert.show("Could not connect to server, please try again later ！", "Error");
}